// pages/exam/exam.js
const config = require('../../config.js')
const http = require('../../http.js')
//获取应用实例
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    position: 0,
    eaxmList: [],
    examMsg: null,
    eaxmList_end:[],
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   this.getExamList(1)
   this.getExamList(2)
  },


  //获取列表数据
  getExamList: function (t) {
    var that = this;
    http.request(
      config.getExamList,
      'POST', {
        examType:[1],
        type: t,
      },
      function (res) {
        if (res.rows != null && res.rows.length > 0) {
          for (var i = 0; i < res.rows.length; i++) {
            var item = res.rows[i]
            item.exam.startTime = item.exam.startTime.substring(0, 16)
            item.exam.endTime = item.exam.endTime.substring(0, 16)
          }
          if(t==1){
            //ing
            that.setData({
              eaxmList: res.rows,
              listLength: res.rows.length,
            })
          }else{
            that.setData({
              eaxmList_end: res.rows,
              end_listLength: res.rows.length,
            })

          }
        } else {
          that.setData({
            listLength: 0,
            examMsg: null
          })
        }

      },
      function (err) {
        wx.showToast({
          title: '数据请求失败',
          icon: 'none',
        })
      }
    )

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


  next: function () {
    if (this.data.position < this.data.listLength - 1) {
      this.data.position++
    } else {
      this.data.position = 0
    }
    this.setData({
      examMsg: this.data.eaxmList[this.data.position]
    })
  },

  signup: function (event) {
    var stu = event.currentTarget.dataset.stu;
    var examid = event.currentTarget.dataset.examid;
    if (stu <= 2) {
      wx.navigateTo({
        url: '../../pages/examination/notice/notice?type=0&examId=' + examid
      })
    }

    if (stu == 3) {
      wx.navigateTo({
        url: '../../pages/examination/notice/notice?type=1&examId=' + examid
      })
    }

    if (stu >= 4) {
      return
    }

  },


  
  lookOver: function (event) {
    var examid = event.currentTarget.dataset.examid;
    wx.navigateTo({
      url: '../../pages/examination/notice/notice?type=2&examId=' +examid
    })
  }
})